package cn.wolfcode.crm.service.impl;

import cn.wolfcode.crm.mapper.ChartMapper;
import cn.wolfcode.crm.query.QueryObject;
import cn.wolfcode.crm.service.IChartService;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

@Service
public class ChartServiceImpl implements IChartService {

    @Autowired
    private ChartMapper chartMapper;

    public List<Map<String, Object>> selectStuReport(QueryObject qo) {
        return chartMapper.selectStuReport(qo);
    }

    /**
     * 根据条件查询员工列表导出到exl
     * @param qo
     * @return
     */

    public Workbook exportXls(QueryObject qo) {
        //创建xls
        Workbook book = new HSSFWorkbook();
        //创建工作簿
        Sheet sheet = book.createSheet();
        //设置第一行的标题
        Row row = sheet.createRow(0);
        row.createCell(0).setCellValue("分组类型");
        row.createCell(1).setCellValue("已付总款");
        row.createCell(2).setCellValue("未付总款");
        row.createCell(3).setCellValue("已付清人数");

        List<Map<String, Object>> list = chartMapper.selectStuReport(qo);


        for(int i=0;i<= list.size()-1;i++){
            Map<String, Object> map = list.get(i);
                row = sheet.createRow(i + 1);
                row.createCell(0).setCellValue(map.get("groupByTypeName").toString());
                row.createCell(1).setCellValue(map.get("waitingFit").toString());
                row.createCell(2).setCellValue(map.get("payFit").toString());
                row.createCell(3).setCellValue(map.get("payState").toString());

        }
        return book;
    }
}
